package ru.gerunn.silent.server;

import java.util.concurrent.Callable;

import ru.gerunn.silent.exception.SilentReadMessageException;
import ru.gerunn.silent.exception.SilentWriteMessageException;
import ru.gerunn.silent.message.Message;
import ru.gerunn.silent.message.TextMessage;
import ru.gerunn.silent.user.User;

public class Authentificator implements Callable<User> {

	private final Session session;

	public Authentificator(final Session session) {
		this.session = session;
	}

	public User call() throws SilentWriteMessageException, SilentReadMessageException {
		Message message;
		session.getWriter().write(new TextMessage("need authorization"));
		message = session.getReader().read();
		return new User(message.toString());
	}

}
